#define _CRT_SECURE_NO_WARNINGS 1

#include<stdio.h>
#include<string.h>

struct stu
{
	char name[20];
	int age;
};
int cmp_struct_name(const void* e3, const void* e4)
{
	return strcmp((char*)e3, (char*)e4);
}
int cmp_int(const void* e1, const void* e2)
{
	return *((int*)e1) - *((int*)e2);
}

void swap(char* str1, char* str2, int size)
{
	int i = 0;
	for (i = 0; i < size; i++)
	{
		char tmp = *str1;
		*str1 = *str2;
		*str2 = tmp;
		str1++;
		str2++;
	}
}

void qsort_bubble_mock(void* base, int num, int size, int(*cmp)(const void* e1, const void* e2))
{
	int i = 0, j = 0;
	for (i = 0; i < num; i++)
	{
		for (j = 0; j < num - i - 1; j++)
		{
			if (cmp((char*)base + j * size, (char*)base + (j + 1) * size) > 0)
			{
				swap((char*)base + j * size, (char*)base + (j + 1) * size, size);
			}
		}
	}
}

int main()
{
	int arr1[] = { 1,4,2,3,5 };
	struct stu s[] = { {"xiao",23},{"zhong",13},{"da",34} };
	int sz1 = sizeof(arr1) / sizeof(arr1[0]);
	int sz2 = sizeof(s) / sizeof(s[0]);
	qsort_bubble_mock(arr1, sz1, sizeof(arr1[0]), cmp_int);
	qsort_bubble_mock(s, sz2, sizeof(s[0]), cmp_struct_name);
	return 0;
}